home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / array.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  856b  |  41 lines

  1. /* array.c  13 */
  2.  
  3. #define FALSE 0
  4. #define TRUE 1
  5. #define MAXENTRY 20
  6.  
  7. long total(); /* Declaration of the function */
  8.  
  9. void main()
  10. {
  11.    int i, number, end = FALSE;
  12.    long sum, data[MAXENTRY];
  13.  
  14.    for(i = 0; i <MAXENTRY && !end; i++)
  15.    {
  16.       printf("Enter %d. value: ", i+1);
  17.       scanf("%6ld", &data[i]); /* 6 digits limit */
  18.       if(!data[i])
  19.          end = TRUE;
  20.    }
  21.  
  22. number = i - end; /* If last entry 0, than one less */
  23. sum = total(data, number);
  24. printf("The Sum of all %d values is %ld\n", number, sum);
  25.   printf("Deviation from Average %.9lf:\n", (double) sum / number);
  26. for(i=0; data[i] > 0; i++)
  27.   printf("Value %d: %5.9lf%%\n", i+1, data[i] * 100.0 / ( (double) sum / number ) - 100.0);
  28. }
  29.  
  30. long total(array, cnt)
  31. long array[];
  32. int cnt;
  33. {
  34.    long sum = 0;
  35.  
  36.    while(cnt--) /* short and precise */
  37.      sum += array[cnt];
  38.    return sum;
  39. }
  40.  
  41.